package cn.tedu.rabbitmqspringboot.m4;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Scanner;

@Component
public class Producer {
        // 在 RabbitAutoConfiguration 自动配置类中创建的工具对象
        @Autowired
        private AmqpTemplate amqpTemplate;

        public  void send(){


//                new Thread(new Runnable() {
//                        @Override
//                        public void run() {
//
//                        }
//                }).start();
                //lamdba 匿名内部类的简写
                new Thread(() ->{
                        while(true){
                                System.out.println("输入消息：");
                                String msg=new Scanner(System.in).nextLine();
                                System.out.println("输入路由键：");
                                String key=new Scanner(System.in).nextLine();
                                amqpTemplate.convertAndSend("direct_logs",key,msg);
                        }
                }).start();
        }
}
